﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using WPF数据采集系统.DAL;
using WPF数据采集系统.Model;

namespace WPF数据采集系统.BLL
{
    public class MainBLL
    {
        DataSql ds = new DataSql();
        public MainBLL()
        {

        }
        public DataResult<List<TesterModel>> InItTesterResult()
        {
            DataResult<List<TesterModel>> result = new DataResult<List<TesterModel>>();
            try
            {
                var sa = ds.GetTesterData();
                result.State = true;
                result.code = 1;
                result.Data = (from q in sa.AsEnumerable()
                               select new TesterModel
                               {
                                   id = q.Field<int>("序号"),
                                   date = q.Field<DateTime>("日期"),
                                   dieluo1 = q.Field<string>("跌落1"),
                                   dieluo2 = q.Field<string>("跌落2"),
                                   vp_dy = q.Field<string>("VP电压"),
                                   sy_time = q.Field<string>("升压时间"),
                                   kl_result = q.Field<string>("开路结果"),
                                   fangdian1 = q.Field<string>("放电1"),
                                   fangdian2 = q.Field<string>("放电2"),
                                   vp_result = q.Field<string>("VP结果"),
                                   dl1_result = q.Field<string>("跌落1结果"),
                                   dl2_result = q.Field<string>("跌落2结果"),
                                   tl_result = q.Field<string>("TL结果"),
                                   th_result = q.Field<string>("TH结果"),
                                   total_result = q.Field<string>("总结果"),
                                   Odd_numbers = q.Field<string>("单号"),
                                   Operator = q.Field<string>("操作人"),
                               }).ToList();
            }
            catch (Exception ex)
            {
                result.Message = "错误消息:" + ex.Message + " 导致异常的实例:" + ex.InnerException + " 对象名:" + ex.Source + " 函数名:" + ex.TargetSite;
            }
            return result;
        }
        public DataResult<List<PlcModel>> LoadPlcInfo()
        {
            DataResult<List<PlcModel>> result = new DataResult<List<PlcModel>>();
            try
            {
                var sa = ds.GetPlcInfo();
                result.State = true;
                result.code = 1;
                result.Data = sa;
            }
            catch (Exception ex)
            {
                result.State = false;
                result.Message = "错误消息:" + ex.Message + " 导致异常的实例:" + ex.InnerException + " 对象名:" + ex.Source + " 函数名:" + ex.TargetSite;
            }
            return result;
        }
        public DataResult<List<PlcMonitorInfo>> LoadPlcMonitorInfo()
        {
            DataResult<List<PlcMonitorInfo>> result = new DataResult<List<PlcMonitorInfo>>();
            try
            {
                var sa = ds.GetPlcMonitorInfo();
                result.State = true;
                result.code = 1;
                result.Data = sa;
            }
            catch (Exception ex)
            {
                result.State = false;
                result.Message = "错误消息:" + ex.Message + " 导致异常的实例:" + ex.InnerException + " 对象名:" + ex.Source + " 函数名:" + ex.TargetSite;
            }
            return result;
        }
        public bool SavePlcData(PlcModel pm)
        {
            try
            {
                return ds.SavePlcData(pm);
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }


    }
}
